package com.business.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.Tag;
import com.business.domain.TagItem;
import com.business.service.TagItemService;
import com.business.service.TagService;
import com.sys.result.PageParam;
import com.sys.result.RequestPageVo;
import com.sys.result.RequestResultVo;
import com.sys.result.ResultVo;

@Controller
@RequestMapping("/business/tag")
public class TagController {
	
	@Resource
	private TagService tagService;
	
	@Resource
	private TagItemService tagItemService;

	@RequestMapping("/toTagPage")
	public String toTagPage(Model model,String title){
		model.addAttribute("title", title);
		return "tag/tagPage";
	}
	
	@RequestMapping("totagItemPage")
	public String totagItemPage(Model model,String title,Integer tagId){
		model.addAttribute("title", title);
		model.addAttribute("tagId", tagId);
		return "tag/tagItemPage";
	}
	
	@RequestMapping("/getTagList")
	public @ResponseBody RequestPageVo<Tag> getTagList(PageParam param,Tag tag){
		
		return tagService.getTagList(param, tag);
	}
	
	@RequestMapping("/deleteTag")
	public @ResponseBody ResultVo deleteTag(Integer id){
		
		return tagService.deleteTag(id);
	}
	@RequestMapping("/saveOrUpdateTag")
	public @ResponseBody ResultVo saveOrUpdateTag(Tag tag){
		
		return tagService.saveOrUpdateTag(tag);
	}
	
	
	@RequestMapping("queryTagItemList")
	public @ResponseBody RequestPageVo<TagItem> queryTagItemList(PageParam param,Integer tagId,String name){
		RequestPageVo<TagItem> pageVo=tagItemService.queryTagItemList(param, tagId,name);
		return pageVo;
	}
	
	@RequestMapping("saveOrUpdateTagItem")
	public @ResponseBody RequestResultVo<TagItem> saveOrUpdateTagItem(TagItem tagItem){
		RequestResultVo<TagItem> ruselt=new RequestResultVo<TagItem>();
		if(tagItem.getId()!=null){
			ruselt=tagItemService.updateTagItem(tagItem);
		}else{
			ruselt=tagItemService.addTagItem(tagItem);
		}
		return ruselt;
	}
	
	@RequestMapping("deleteTagItem")
	public @ResponseBody RequestResultVo<TagItem> deleteTagItem(Integer id){
		RequestResultVo<TagItem> ruselt=new RequestResultVo<TagItem>();
		ruselt=tagItemService.deleteTagItem(id);
		return ruselt;
	}
	
}
